<?php
class Zend_View_Helper_Name extends Zend_View_Helper_Abstract
{
	public function getShowName($uid, $type = 0){
		$orm = ORM::getInstance();
		$userinfoDAO = $orm->createDAO("_users_info")->alias('u');
		$userinfoDAO ->with_users_info_app_ext(array('user_id'=>'user_id'))->alias('a');
		$userinfoDAO ->with_users_info_app_list(array('user_appid'=>'wd_app_id'))->alias('l');
		$userinfoDAO ->select('u.user_id, u.user_name, u.real_name, u.user_appid, u.user_appname, u.department, a.user_app_ext1, l.wd_app_describe');
		$userinfoDAO ->findUser_id($uid);
		$userinfo = $userinfoDAO->get();

		if($userinfo[0]['real_name']){
			$user_name  = $userinfo[0]['real_name'];
		}else{
// 			if($userinfo[0]['user_appid']){
// 				$user_name = $this->getRtxName($userinfo[0]['user_name']);
// 			}else{
// 				$user_name  = $userinfo[0]['user_name'];
// 			}
			$user_name  = $userinfo[0]['user_name'];
		}
		
		$ext = $source = $depart = '';
		
		if($userinfo[0]['wd_app_describe']){
			$source = $userinfo[0]['wd_app_describe'];
		}else{
			$source = '互联网注册用户';
		}
		
		if($userinfo[0]['user_app_ext1']){
			$depart = $userinfo[0]['user_app_ext1'];
		}else{
			$depart = $userinfo[0]['department'];
		}
		
		if($type == 1){
			if($depart){
				$ext = '('.$source.'-'.$depart.')';
			}else{
				$ext = '('.$source.')';
			}
		}
		
		$user_name .= $ext;
		
		return $user_name;
	}
	
	protected function getRtxName($rtxname){
		$name = strstr($rtxname, '@', true);
		$name = ltrim($name, '@');
		return $name;
	}
}